<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Label;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class LabelController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Label(), function (Grid $grid) {
            $grid->model()->orderBy('sort');
            $grid->column('name');
            $grid->column('image')->image('',50,50);
            $grid->column('status')->switch();
            $grid->column('sort')->orderable();
            $grid->column('created_at');

        
            $grid->quickSearch(['name']);
            $grid->enableDialogCreate();
            $grid->disableEditButton();
            $grid->showQuickEditButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Label(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('image');
            $show->field('status');
            $show->field('sort');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Label(), function (Form $form) {

            $form->text('name');
            $form->image('image')->autoUpload()->uniqueName()->move('label');
            $form->switch('status')->default(1);
            $form->hidden('sort')->default(0);
        

        });
    }
}
